﻿using System.Collections.Generic;
using System.Linq;
using Accountant.DataModel;
using Caliburn.Micro;

namespace Accountant.ViewModels
{
  public class AddAccountViewModel : Screen
  {
    public override string DisplayName { get { return "Добавление счета"; } set { } }

    public AccountantContext Context { get; set; }
    public List<Account> PossibleBase { get; set; }
    public List<Currency> PossibleCurrencies { get; set; }
    public Account AccountUnderCreation { get; private set; }

    public AddAccountViewModel(AccountantContext context, Account defaultBase)
    {
      Context = context;
      AccountUnderCreation = new Account();
      PossibleBase = context.Accounts
        .Where(a => !a.IsHidden && !a.IsSealed)
        .ToList();
      AccountUnderCreation.BaseAccount = defaultBase;
      PossibleCurrencies = context.Currencies.ToList();
    }

    public AddAccountViewModel(Account accountToEdit, AccountantContext context)
    {
      Context = context;
      AccountUnderCreation = new Account();
      PossibleBase = context.Accounts
        .Where(a => !a.IsHidden && !a.IsSealed)
        .ToList();
      AccountUnderCreation = accountToEdit;
      PossibleCurrencies = context.Currencies.ToList();
    }

    public void Accept()
    {
      TryClose(true);
    }
    public void Cancel()
    {
      TryClose(false);
    }
  }
}